package PROYECTO2.src.Naves.Jugador;
import java.awt.event.KeyEvent;
import java.net.URL;
import javax.swing.ImageIcon;

import PROYECTO2.src.Explosiones_Disparos.Shot;
import PROYECTO2.src.Explosiones_Disparos.Explosion;
import PROYECTO2.src.Naves.Spaceship;

public class Colonial extends Spaceship {
	protected ImageIcon icon;	
	protected int power;
	protected static URL explode = (Spaceship.class.getClassLoader().getResource("PROYECTO2/src/img/Explosiones/player.gif"));
	
	public Colonial(int life, int s, ImageIcon icon,int w,int h){
		super(life, s, icon, new ImageIcon(explode), w, h);
		this.icon = icon;		
		speed=s;
		setColonial(this);
		speedLaser = 20;
		power = 1;
		score = 0;
	}
	
	public void keyPressed(KeyEvent e) {
		
        int key = e.getKeyCode();
        
        if (key == KeyEvent.VK_SPACE) {
            if(cantShot() && getVisible()){
            	shooting();
            }
        }
       
        if (key == KeyEvent.VK_LEFT) {
        	dx = -speed;
        }
        
        if (key == KeyEvent.VK_RIGHT) {
        	dx = speed;
        }
       
        if (key == KeyEvent.VK_UP) {
        	dy = -speed;
        }
        
        if (key == KeyEvent.VK_DOWN) {
        	dy = speed;
        }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;            
        }
      
        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;            
        }
        
        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }
       
        if (key == KeyEvent.VK_UP) {
            dy = 0;
        }
    }
    
    public void shooting() {
    	
    	Shot d = new Shot(x + width/2 , y, 0, 1, speedLaser);
    	Shot[] array = d.cloneLevel(power);
    	if(cantShot()){
    		for(int i = 0;i<array.length;i++){
    			game.addShotColonial(array[i]);
    		}
    	}
    }

	 public void move() {
		 
		 if(x >= minWidth + width*2)
			x += dx;
		 else
			x = 1;
		 
		 if( x <= maxWidth - width*2)
			x += dx;
		 else
			 x = maxWidth  - width*2 - 1;
		 
		 if(y >= maxHeight + height*2 )
	        y += dy;
		 else
			y = 1;
		 
		 if(y <= minHeight - height)
			y += dy;
		 else
			y = minHeight - height - 7;
   }

		public void setLife(int vd) {
			
			if(life <= 0) 
				setVisible();
			else
				life-=vd;
		}
	 
	@Override
	public Explosion getExplosion() {
		return new Explosion(x + width/2, y + height/2, new ImageIcon(explode), width, height);
	}

	public int getScore() {
		return score;
	}

	public void setScore(int puntaje) {
		score += puntaje;
	}
}